using System;
using System.Linq;
using JNPF.Utils;
using System.Threading.Tasks;
using JNPF.Data;
using JNPF.Data.Util;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using JNPF.Basics.Models;

namespace JNPF.Basics.Logic
{
    public class CustomerlitigationService: DataFactory, CustomerlitigationIService
    {
		/// <summary>
		/// 获取信息
		/// </summary>
		/// <param name="id">主键id</param>
		/// <returns></returns>
		public async Task<CustomerlitigationEntity> GetInfo(int id)
		{
			using (var db = this.Basic)
			{
				return await db.GetEntityAsync<CustomerlitigationEntity>(m => m.Id == id);
			}
		}

		/// <summary>
		/// 列表（分页）
		/// </summary>
		/// <param name="input">请求参数</param>
		/// <returns></returns>
		public async Task<PageResult<CustomerlitigationEntity>> GetPageList(CustomerlitigationListQueryInput input)
		{
			using (var db = this.Basic)
			{
				var queryWhere = ExtLinq.True<CustomerlitigationEntity>();
				var queryParam = input.queryJson.ToObject();
				//查询原告
				if (!string.IsNullOrEmpty(input.plaintiff))
				{
					queryWhere = queryWhere.And(m => m.Plaintiff.Contains(input.plaintiff));
				}

                if (input.customerId.HasValue)
                {
                    queryWhere = queryWhere.And(m => m.CustomerId == input.customerId.Value);
                }
                queryWhere = queryWhere.And(m => m.DeleteMark == 0);
                return await db.GetIQueryable<CustomerlitigationEntity>().Where(queryWhere).GetPageResultAsync(input);
			}
		}

		/// <summary>
		/// 创建信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Create(CustomerlitigationEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.InsertAsync(entity);
			}
		}

		/// <summary>
		/// 更新信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Update(CustomerlitigationEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.UpdateAsync(entity);
			}
		}

		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="entity">实体对象</param>
		/// <returns></returns>
		public async Task<int> Delete(CustomerlitigationEntity entity)
		{
			using (var db = this.Basic)
			{
				return await db.DeleteAsync(entity);
			}
		}

		/// <summary>
		/// 列表
		/// </summary>
		/// <param name="input">请求参数</param>
		/// <returns></returns>
		public async Task<List<CustomerlitigationEntity>> GetList(CustomerlitigationListQueryInput input)
		{
			using (var db = this.Basic)
			{
				var queryWhere = ExtLinq.True<CustomerlitigationEntity>();
				//查询原告
				if (!string.IsNullOrEmpty(input.plaintiff))
				{
					queryWhere = queryWhere.And(m => m.Plaintiff.Contains(input.plaintiff));
				}
                queryWhere = queryWhere.And(m => m.DeleteMark == 0);
                return await db.GetIQueryable<CustomerlitigationEntity>().Where(queryWhere).ToListAsync();
			}
		}


    }
}